package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.ICustomerDao;
import com.hy.erp.inventory.pojo.Customer;
import com.hy.erp.inventory.pojo.interfaces.ICustomer;
import com.hy.erp.inventory.service.interfaces.ICustomerService;
/**
 * 
 * <ul>
 * <li>开发作者：李冰</li>
 * <li>设计日期：2010-10-13；时间：上午09:17:55</li>
 * <li>类型名称：CustomerService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
@ Name ( "customerService" )
@ Scope ( ScopeType.STATELESS )
@ Stateless
public class CustomerService extends AbstractBusinessService < ICustomer > implements ICustomerService
{

	@ Override
	public boolean addCustomer (
									ICustomer customer )
	{






		if ( null == customer)
		{
			return true ;
		}
		
		else
		{
			System.out
						.println ("ssssssssssssssssssssssffffffffffffffffhghhhhhhhhhhhhhhhhhhhhhh") ;


			ICustomerDao customerDao =
			                       ( ICustomerDao ) this
			                                          .getDao ( ICustomer.class ) ;
			
			return customerDao
			                .persist ( customer ) ;
		}
		
	
	
	
	
	
	
	}

	@ Override
	public boolean modifyCustomer (
									ICustomer customer )
	{






		if ( ( null == customer )
			     || ( null == customer
			                                .getIdentifier ( ) )
			     || ( customer
			                        .getIdentifier ( )
			                        .trim ( )
			                        .length ( ) == 0 ) )
			{
				return true ;
			}
			else
			{
				ICustomerDao customerDao =
                    ( ICustomerDao ) this
                                       .getDao ( ICustomer.class ) ;

		
					
				if ( null == customer )
				{
					throw new ArchitectureFoundationException  (
					                                            "修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
				}
				
				
				return (customerDao
				                  .merge ( customer ) != null ) ;
			}
		
	
	
	
	
	
	
	
	}

	@ Override
	public Integer removeCustomer (
									String [ ] customerIds )
	{







		if ( ( null == customerIds)
			     || ( customerIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{


				ICustomerDao customerDao =
                    ( ICustomerDao ) this
                                       .getDao ( ICustomer.class ) ;

		
				return customerDao
				                .remove ( customerIds ) ;
			}
	
	
	
	
	
	
	
	}

	@ SuppressWarnings ( "unused" )
	@ Override
	public List < ICustomer > getCustomerById (
												String [ ] id )
	{
		if(id.length!=0||id!=null){
			ICustomerDao customerDao =
	            ( ICustomerDao ) this
	                               .getDao ( ICustomer.class ) ;
			
			return customerDao.findByIdentifier ( id );
		}
		else
		{
			return null;
		}
		
	
	}

	@ Override
	public String [ ] addCustomers (
										Object [ ] customers )
	{
		ICustomerDao customerDao =
            ( ICustomerDao ) this
                               .getDao ( ICustomer.class ) ;
		

		Customer[] customerss=new Customer[customers.length];
					for(int i=0;i<customers.length;i++)
					{
						Customer customers2=( Customer ) customers[i];
						customerss[i]=customers2;
					}
					return customerDao
					                .persist ( customerss ) ;

		
	}

	@ Override
	public List < ICustomer > getAllCustomer ( )
	{
		ICustomerDao customerDao =
            ( ICustomerDao ) this
                               .getDao ( ICustomer.class ) ;


		return customerDao
		                .find ( ) ;
	}

	@ Override
	public String [ ] modifyCustomer (
										Object [ ] customers )
	{

		ICustomerDao customerDao =
            ( ICustomerDao ) this
                               .getDao ( ICustomer.class ) ;
		

		Customer[] customerss=new Customer[customers.length];
					for(int i=0;i<customers.length;i++)
					{
						Customer customers2=( Customer ) customers[i];
						customerss[i]=customers2;
					}
					return customerDao
					                .merge   ( customerss ) ;

		
	
	}


}
